package com.device.operating.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.device.operating.dao.DepartmentRepository;
import com.device.operating.dao.GroupRepository;
import com.device.operating.dao.RoleRepository;
import com.device.operating.dao.UgRepository;
import com.device.operating.dao.UgfuncRepository;
import com.device.operating.dao.UgfunctypeRepository;
import com.device.operating.dao.UserRepository;
import com.device.operating.entity.Department;
import com.device.operating.entity.Func;
import com.device.operating.entity.Grouptab;
import com.device.operating.entity.Role;
import com.device.operating.entity.Ugfunc;
import com.device.operating.entity.Ugfunctype;
import com.device.operating.entity.User;
import com.device.operating.service.DepartmentService;
import com.device.operating.service.FuncService;
import com.device.operating.service.GroupService;
import com.device.operating.service.RoleService;
import com.device.operating.service.UgfuncService;
import com.device.operating.service.UgfunctypeService;
import com.device.operating.service.UserService;

@Service("UgfunctypeService")
@Transactional(propagation=Propagation.REQUIRED)
public class UgfunctypeServiceImpl implements UgfunctypeService{
	
	@Autowired
	private UgfunctypeRepository UgfunctpyeRepository;

	@Override
	public void addugfunctype(Ugfunctype ugfunctype) {
		// TODO Auto-generated method stub
		UgfunctpyeRepository.save(ugfunctype);
	}

	@Override
	public void deleteugfunctype(String ugfunctypeId) {
		// TODO Auto-generated method stub
		UgfunctpyeRepository.delete(ugfunctypeId);
	}

	@Override
	public void deleteugfunctypebyugId(String ugId) {
		// TODO Auto-generated method stub
		List<Ugfunctype> list=UgfunctpyeRepository.findByUgId(ugId);
		for(Ugfunctype uf:list){
			UgfunctpyeRepository.delete(uf.getUgfunctypeId());
		}
	}

	@Override
	public List<Ugfunctype> querybyugIdandugtype(String ugId, String ugtype) {
		// TODO Auto-generated method stub
		return UgfunctpyeRepository.findByUgIdAndUgtype(ugId, ugtype);
	}

	@Override
	public Ugfunctype querybyugIdandugtypeandfunctypeId(String functypeId,
			String ugId, String ugtype) {
		// TODO Auto-generated method stub
		return UgfunctpyeRepository.findByUgIdAndUgtypeAndFunctypeId(ugId, ugtype, functypeId);
	}

	@Override
	public Ugfunctype querybyugIdandugtypeandfunctypecode(String functypecode,
			String ugId, String ugtype) {
		// TODO Auto-generated method stub
		return UgfunctpyeRepository.findByUgIdAndUgtypeAndFunctypecode(ugId, ugtype, functypecode);
	}

	@Override
	public List<Ugfunctype> querybyugIdandugfuncyupesort(String ugId, String ugfunctypesort) {
		// TODO Auto-generated method stub
		return UgfunctpyeRepository.findByUgIdAndFunctypesortOrderByTypenumAsc(ugId, ugfunctypesort);
	}

	@Override
	public List<Ugfunctype> querybyfunctypeId(String functypeId) {
		// TODO Auto-generated method stub
		return UgfunctpyeRepository.findByFunctypeId(functypeId);
	}

	
	
}
